window.pageTools = window.pageTools || {};
(function () {
    function Login(isLogin, selector, eventListener) {
        this.isLogin = isLogin;
        this.selector = $(selector);
        this.init();
        this.eventListener = eventListener;
    }
    Login.prototype.init = function () {
        var isShow = this.isLogin ? 'none' : 'block';
        var buttonText = this.isLogin ? '登录' : '注册';
        // 添加对话框DOM
        this.dialog = $('<div class="dialog">\
                            <button class="close-btn">&times;</button>\
                            <div class="input-box">\
                                <input type="text" placeholder="用户名">\
                                <input type="password" placeholder="密码">\
                                <input type="password" placeholder="确认密码" class="again-pwd\
                                <button class="btn"></button>\
                            </div>\
                        </div>');

        this.selector.append(this.dialog);

        $('.again-pwd').css('display', isShow);

        $('.btn').html(buttonText).click(function () {
            this.dialog.remove();
            this.dialog = null;
            this.eventListener();
        }.bind(this));

        $('.close-btn').click(function () {
            this.dialog.remove();
            this.dialog = null;
            this.eventListener();
        }.bind(this));
    }
    pageTools.Login = Login;
})();